<template>
  <div class="comment_list">
    <!-- <div
        :class='cl_top_tab_status == 0?"cl_top_tab_active":""'
        @click="cl_top_tab_click(0)"
      >待评价</div>
      <div
        :class='cl_top_tab_status == 1?"cl_top_tab_active":""'
        @click="cl_top_tab_click(1)"
      >已评价</div> -->
    <!-- <div :style="'left:'+ cl_top_tab_left +';'"></div> -->
    <div class="cl_top_tab">
      <tab
        :line-width="2"
        :custom-bar-width="customBarWidth"
      >
        <tab-item
          :selected="cl_top_tab_status === 0"
          @on-item-click="cl_top_tab_click(0)"
        >
          <p>待评价</p>
        </tab-item>
        <tab-item
          :selected="cl_top_tab_status === 1"
          @on-item-click="cl_top_tab_click(1)"
        >
          <p>已评价</p>
        </tab-item>
      </tab>
    </div>
    <div style="height: 44px;"></div>
    <div
      ref="slide"
      :style="`height:${WinHeight}px;width:${WinWidth}px`"
      class="slides"
    >
      <div
        class="slide-group"
        ref="slideGroup"
        :style="`width:${2 * 100}%`"
      >
        <div
          class="item"
          v-for="(item,index) in 2"
          :key="index"
          :style="`height:${WinHeight}px;width:${WinWidth}px`"
        >
          <section
            ref="wrapper"
            v-if="cl_top_tab_status === index"
            style="height:100%;overflow: hidden;"
          >
            <div>
              <div class="cl_top_box">
                <!-- 待评价 -->
                <div v-if="cl_top_tab_status == 0">
                  <div
                    class="cl_box_item"
                    v-for="(item,index) in cl_top_box_list"
                    :key="index"
                  >
                    <div class="cl_box_item_title">
                      {{item.title}}
                    </div>
                    <div class="cl_box_item_tea">所属老师: {{item.names}}</div>
                    <div
                      class="cl_box_item_btn"
                      @click="cl_box_one_click(item)"
                    >立即评价</div>
                  </div>
                  <kong
                    :type='type1'
                    v-show="com_kong1"
                  ></kong>
                </div>

                <!-- 已评价 -->
                <div v-if="cl_top_tab_status == 1">
                  <div
                    class="cl_box_item"
                    v-for="(item,index) in cl_top_tab_list"
                    :key="index"
                  >
                    <div class="cl_box_two_xing">
                      <div>{{cl_top_text[item.score - 1]}}</div>
                      <img
                        :src="cl_top_img[item.img]"
                        alt=""
                      >
                    </div>
                    <div class="cl_box_two_content">{{item.content}}</div>
                    <div class="cl_box_item_titles">{{item.title}}</div>
                    <div class="cl_box_item_tea">所属老师: {{item.c_name}}</div>
                    <div
                      class="cl_box_item_btn_two"
                      @click="cl_box_two_click(item)"
                    >修改评价</div>
                  </div>
                  <kong
                    :type='type1'
                    v-show="com_kong2"
                  ></kong>
                </div>
              </div>
            </div>
          </section>

        </div>
      </div>
    </div>

  </div>
</template>

<script>
import {
  Tab,
  TabItem,
  LoadMore
} from 'vux'
import BScroll from 'better-scroll'
import { mapState } from 'vuex'
import { tobe_evaluate, evaluate } from '@/api/comment_list'
import kong from '@/components/public/kong.vue'
export default {
  components: {
    kong,
    Tab,
    TabItem,
    LoadMore
  },
  watch: {
    osos (v) {
      this.cl_top_tab_status = this.slide.getCurrentPage().pageX
      this.initWrapper()
    }
  },
  data () {
    return {
      osos: '',
      WinHeight: '',
      WinWidth: '',
      customBarWidth: '1',
      type1: '评价',
      com_kong1: true,
      com_kong2: true,
      cl_top_text: ['大失所望', '比较一般', '还算不错', '非常满意', '物超所值'],
      cl_top_img: [
        'https://o6wndwjxn.qnssl.com/Nostar.svg', // 0
        'https://o6wndwjxn.qnssl.com/After%20a%20week.svg', // 1
        'https://o6wndwjxn.qnssl.com/Two%20star.svg', // 2
        'https://o6wndwjxn.qnssl.com/samsung.svg', // 3
        'https://o6wndwjxn.qnssl.com/A%20four-star.svg', // 4
        'https://o6wndwjxn.qnssl.com/The%20five-star.svg' // 5
      ],
      cl_top_tab_left: 'calc(25% - 15px)',
      cl_top_tab_status: 0,
      cl_top_box_list: [],

      cl_top_tab_list: []
    }
  },
  computed: {
    ...mapState({
      app_id: state => state.app_id,
      user_id: state => state.member_id
    })
  },
  created () {
    this.getComment()
    this.getCommented()
  },
  mounted () {
    this.$nextTick(() => {
      this.customBarWidth = (36 / 750) * 100 + 'vw'
      this.WinHeight = document.documentElement.clientHeight - 50
      this.WinWidth = document.documentElement.clientWidth
      this.initTab()
      this.initWrapper()
    })
  },
  methods: {
    initWrapper () {
      this.$nextTick(() => {
        let _this = this
        this.scroll = new BScroll(this.$refs.wrapper[0], {
          click: true,
          scrollY: true,
          scrollX: false,
          tap: true,
          bounce: false,
          probeType: 3,
          pullUpLoad: {
            threshold: 10
          }
        })
        // 上拉加载
        this.scroll.on('scroll', function (ob) {
          _this.scrollY = ob.y
        })
      })
    },
    initTab () {
      let _this = this
      this.slide = new BScroll(this.$refs.slide, {
        scrollX: true,
        scrollY: false,
        momentum: false,
        pullUpLoad: {
          threshold: 0
        },
        snap: {
          loop: false,
          threshold: 0,
          speed: 300
        },
        bounce: false,
        stopPropagation: true,
        click: this.click
      })
      this.slide.on('scrollEnd', function (ob) {
        _this.osos = ob.x
      })
    },
    getCommented () {
      let requery = {
        app_id: this.app_id,
        user_id: this.user_id,
        page: 1,
        pageshow: 1000
      }
      evaluate(requery).then(res => {
        let { code, data } = res.data
        console.log(data)
        if (code == 200) {
          this.com_kong2 = false
          this.cl_top_tab_list = data
          for (var i = 0; i < this.cl_top_tab_list.length; i++) {
            this.cl_top_tab_list[i].img = this.cl_top_tab_list[i].score
          }
        } else {
          this.com_kong2 = true
        }
      })
    },
    getComment () {
      let requery = {
        app_id: this.app_id,
        user_id: this.user_id,
        page: 1,
        pageshow: 1000
      }
      tobe_evaluate(requery).then(res => {
        this.$store.commit('updateLoadingStatus', { isLoading: false })
        let { code, data } = res.data
        if (code == 200) {
          this.com_kong1 = false
          this.cl_top_box_list = data
        } else {
          this.com_kong1 = true
        }
      })
    },
    cl_box_one_click (e) {
      this.$router.push({
        path: '/comment',
        query: {
          parameter: e,
          status: 1
        }
      })
    },
    cl_box_two_click (e) {
      this.$router.push({
        path: '/comment',
        query: {
          parameter: e,
          status: 2
        }
      })
    },
    cl_top_tab_click (e) {
      this.slide.goToPage(e)
      this.cl_top_tab_status = e
      if (e == 0) {
        this.cl_top_tab_left = 'calc(25% - 15px)'
      } else {
        this.cl_top_tab_left = 'calc(75% - 15px)'
      }
    }
  }
}
</script>
<style>
.comment_list /deep/ .vux-tab .vux-tab-item.vux-tab-selected {
  font-family: PingFangSC-Semibold;
  color: #333333;
}
</style>

<style scoped>
.slides {
  width: 100%;
  overflow: hidden;
}
.slide-group {
  display: flex;
}
.cl_top_tab {
  position: fixed;
  left: 0;
  top: 0;
  width: 100%;
  height: 44px;
  border-bottom: 1px solid #e6e6e6;
  display: flex;
  text-align: center;
  line-height: 44px;
  font-size: 14px;
  color: #666666;
  background: white;
  z-index: 100;
}
.cl_top_tab > div {
  flex: 1;
}
.cl_top_tab > div:nth-child(3) {
  position: absolute;
  transition: all 0.5s cubic-bezier(1, 0.09, 0.1, 1);
  bottom: 0px;
  width: 30px;
  height: 3px;
  background: #f29911;
}
.cl_top_tab_active {
  font-size: 15px;
  color: #f29911;
  font-weight: bold;
}
.cl_top_box {
  width: 90%;
  margin: 0 5%;
}
.cl_box_item {
  background: #f7f7f7;
  margin-top: 20px;
  padding: 15px;
  border-radius: 6px;
  overflow: hidden;
}
.cl_box_item_title {
  font-family: PingFangSC-Regular;
  font-size: calc(100vw * 30 / 750);
  color: #333;
}
.cl_box_item_titles {
  font-family: PingFangSC-Regular;
  font-size: calc(100vw * 30 / 750);
  color: #666;
}
.cl_box_item_tea {
  font-size: 12px;
  color: #999999;
  margin: 15px 0;
}
.cl_box_item_btn,
.cl_box_item_btn_two {
  font-family: PingFangSC-Regular;
  font-size: calc(100vw * 30 / 750);
  color: #da4131;
  font-size: 15px;
  text-align: center;
  height: calc(100vw * 80 / 750);
  line-height: calc(100vw * 80 / 750);
  border-radius: calc(100vw * 40 / 750);
  border: 1px solid #da4131;
}
/* .cl_box_item_btn_two {
  color: #999999;
  border: 1px solid #bbbbbb;
} */
.cl_box_two_xing {
  height: 20px;
  line-height: 20px;
  position: relative;
  margin-top: 5px;
}
.cl_box_two_xing > * {
  display: inline-block;
  text-align: left;
}
.cl_box_two_xing > div {
  font-size: 12px;
  color: #ff9300;
}
.cl_box_two_xing > img {
  margin-left: 7px;
  margin-top: -5px;
  height: 15px;
}
.cl_box_two_content {
  padding: 15px 0;
  margin-bottom: 15px;
  font-size: 14px;
  color: #1a1a1a;
  border-bottom: 1px solid #dbdadb;
}
.cl_box_item:last-child {
  margin-bottom: 20px;
}
</style>
// 			cl_top_tab_requery(){
// 				for(var i = 0 ; i < this.cl_top_tab_list.length ; i ++){
// 					if(this.cl_top_tab_list[i].fen>0 && this.cl_top_tab_list[i].fen<=0.5){
// 						this.cl_top_tab_list[i].fen	= 1
// 						this.cl_top_tab_list[i].img = 1
// 					}else
// 					if(this.cl_top_tab_list[i].fen>0.5 && this.cl_top_tab_list[i].fen<=1){
// 						this.cl_top_tab_list[i].fen	= 1
// 						this.cl_top_tab_list[i].img = 2
// 					}else
// 					if(this.cl_top_tab_list[i].fen>1 && this.cl_top_tab_list[i].fen<=1.5){
// 						this.cl_top_tab_list[i].fen = 2
// 						this.cl_top_tab_list[i].img = 3
// 					}else
// 					if(this.cl_top_tab_list[i].fen>1.5 && this.cl_top_tab_list[i].fen<=2){
// 						this.cl_top_tab_list[i].fen = 2
// 						this.cl_top_tab_list[i].img = 4
// 					}else
// 					if(this.cl_top_tab_list[i].fen>2 && this.cl_top_tab_list[i].fen<=2.5){
// 						this.cl_top_tab_list[i].fen = 3
// 						this.cl_top_tab_list[i].img = 5
// 					}else
// 					if(this.cl_top_tab_list[i].fen>2.5 && this.cl_top_tab_list[i].fen<=3){
// 						this.cl_top_tab_list[i].fen = 3
// 						this.cl_top_tab_list[i].img = 6
// 					}else
// 					if(this.cl_top_tab_list[i].fen>3 && this.cl_top_tab_list[i].fen<=3.5){
// 						this.cl_top_tab_list[i].fen = 4
// 						this.cl_top_tab_list[i].img = 7
// 					}else
// 					if(this.cl_top_tab_list[i].fen>3.5 && this.cl_top_tab_list[i].fen<=4){
// 						this.cl_top_tab_list[i].fen = 4
// 						this.cl_top_tab_list[i].img = 8
// 					}else
// 					if(this.cl_top_tab_list[i].fen>4 && this.cl_top_tab_list[i].fen<=4.5){
// 						this.cl_top_tab_list[i].fen = 5
// 						this.cl_top_tab_list[i].img = 9
// 					}else
// 					if(this.cl_top_tab_list[i].fen>4.5 && this.cl_top_tab_list[i].fen<=5){
// 						this.cl_top_tab_list[i].fen = 5
// 						this.cl_top_tab_list[i].img = 10
// 					}
// 				}
// 			}
